/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.dao.hibernate;

import com.minierp.dao.AdjustBillItemDao;
import com.minierp.dao.hibernate.BaseDaoImpl;
import java.sql.SQLException;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

public class AdjustBillItemDaoImpl extends BaseDaoImpl
		implements
			AdjustBillItemDao {
	public List getListByAdjustBill(long billId) {
		String sql = "from com.minierp.model.AdjustBillItem s where s.billId="
				+ billId + " order by s.id";
		return this.getHibernateTemplate().find(sql);
	}

	public List getList(String billType, long billId, boolean justExamined) {
		String sql = "select b,s from com.minierp.model.AdjustBill b ,com.minierp.model.AdjustBillItem s where b.id=s.billId and b.relType=:relType and s.businessBillId="
				+ billId + " and b.enabled=\'Y\'";
		if (justExamined) {
			sql = sql + " and b.examined=\'Y\'";
		}

		sql = sql + " order by s.id";
		Session sess = null;

		List arg8;
		try {
			sess = this.getSession();
			Query q = sess.createQuery(sql);
			q.setString("relType", billType);
			arg8 = q.list();
		} finally {
			if (sess != null) {
				this.releaseSession(sess);
			}

		}

		return arg8;
	}

	public int delete(final long id) {
		Object obj = this.getHibernateTemplate().execute(
				new HibernateCallback() {
					public Object doInHibernate(Session session)
							throws HibernateException, SQLException {
						String hql = "delete com.minierp.model.AdjustBillItem where id=:id";
						return new Integer(session.createQuery(hql)
								.setLong("id", id).executeUpdate());
					}
				});
		return ((Integer) obj).intValue();
	}

	public int deleteByAdjustBillId(final long billId) {
		Object obj = this.getHibernateTemplate().execute(
				new HibernateCallback() {
					public Object doInHibernate(Session session)
							throws HibernateException, SQLException {
						String hql = "delete com.minierp.model.AdjustBillItem where billId=:billId";
						return new Integer(session.createQuery(hql)
								.setLong("billId", billId).executeUpdate());
					}
				});
		return ((Integer) obj).intValue();
	}
}